'''
Created on Dec 13, 2011

@author: aren1
'''

import thread
import time
import runner
import robot
import interface

buffKey1 = 0x31
buffKey2 = 0x32

isPause = False;

lock = thread.allocate_lock()

def timer(interval, key):
    while True:
        time.sleep(interval)
        pause()
        time.sleep(2)
        print "press at ", key
        interface.pressAt(key)
        time.sleep(5)
        notify()
            
def pause():
    global isPause
    lock.acquire()
    isPause = True
    lock.release()

def notify():
    global isPause
    lock.acquire()
    isPause = False
    lock.release()
    robot.notify()
    runner.notify()

def isPaused():
    global isPause
    return isPause

def doWork():
    thread.start_new_thread(timer, (5, buffKey1))
    thread.start_new_thread(timer, (10, buffKey2))